import React from "react";
import { Link, Routes, Route, useLocation } from "react-router-dom";

const Home = () => {
  return <div>这是首页</div>;
};
const About = () => {
  return <div>这是关于页</div>;
};
const Detail = () => {
  // search字符串是在location对象下的
  const location = useLocation();
  console.log(location);
  return <div>这是详情页</div>;
};

const App = () => {
  return (
    <>
      <h2>路由基础-v6</h2>
      <ul>
        <li>
          <Link to="/">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
        <li>
          <Link to="/detail?id=234" state="999">
            详情页
          </Link>
        </li>
        <li>
          <Link
            // state不能再to里面传了
            // state变成了一个单独的属性
            to={{
              pathname: "/detail",
              search: "?id=567",
              hash: "#trhh",
            }}
            state={{
              x: 10,
            }}
          >
            详情页
          </Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/" element={<Home />}></Route>
        <Route path="/about" element={<About />}></Route>
        <Route path="/detail" element={<Detail />}></Route>
      </Routes>
    </>
  );
};

export default App;
